import React, {ChangeEventHandler} from 'react';
import BaseEntity from "../../type/entity";
import {DatePicker, Form} from "antd";
interface IProps<T> {
    name: keyof T,
    lastName?: keyof T,
    label: string,
    placeholder?: string,
    required?: boolean,
    disabled?: boolean
    onChange?: ChangeEventHandler<HTMLInputElement> | undefined,
    showTime?: boolean,
}

/**
 * 日期选择表单
 */
const InputDate = <T extends BaseEntity>(props: IProps<T>) => {
    const { name, label } = props;
    return (
        <Form.Item<T>
            name={name as any}
            label={label}
            required={props.required}
            rules={[{required: props.required, message: `${label}不能为空!` }]}
        >
            <DatePicker disabled={props.disabled} format={props.showTime ? "YYYY-MM-DD HH:mm:ss" : "YYYY-MM-DD"} showTime={props.showTime}/>
        </Form.Item>
    );
};

export default InputDate;